﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MAPDavy.Entities;

namespace MAPDavy.Repository
{
    public class LogRepository:MasterRepository,ILogRepository
    {
        public void AddLog(Log log)
        {
            var existe = (from l in Context.Logs
                          where l.Id == log.Id
                          select l).SingleOrDefault();

            if (existe == null)
            {
                Context.Logs.Add(log);
                Context.SaveChanges(); 
            }
        }

        public void RemoveLog(int id)
        {
            var existe = (from l in Context.Logs
                          where l.Id == id
                          select l).SingleOrDefault();

            if (existe != null)
            {
                Context.Logs.Remove(existe);
                Context.SaveChanges();
            }
        }

        public Log GetFromLogById(int id)
        {
            var query = from l in Context.Logs
                          where l.Id == id
                          select l;

            return query.SingleOrDefault();
        }
    }
}
